using System;
using System.Collections.Generic;
using HR60_PanelSoft.FileUtils;
using HR60_PanelSoft.Model.BaseModel;

namespace HR60_PanelSoft.Model
{
	/// <summary>
	/// 设备创建器
	/// </summary>
	public class DeviceCreator
	{
		/// <summary>
		/// 设备类型全集
		/// </summary>
		public List<DeviceType> deviceTypes = null;

		/// <summary>
		/// 从文件载入类型全集
		/// </summary>
		public void loadTypes()
		{
			deviceTypes = JsonFileUtils.loadDeviceTypes ();
		}

		/// <summary>
		/// 获得设备类型全集
		/// </summary>
		/// <returns>The types.</returns>
		public List<DeviceType> getTypes()
		{
			return deviceTypes;
		}

		/// <summary>
		/// 根据类型创建设备
		/// </summary>
		/// <param name="type">Type.</param>
		public Device create(DeviceType type)
		{
			Device device = new Device ();
			device.type = type;
			device.nickName = type.name;

			// 初始化子设备列表
			if (type.subDeviceType != null)
			{
				for (int i=0; i<type.subDeviceMax; i++)
				{
					Device sub = new Device ();
					sub.type = type.subDeviceType;
					sub.nickName = "分机" + (i+1);
					device.childDevices.Add (sub);
				}
			}

			return device;

		}
	}
}

